import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

/**
 * @author: Themberfue
 * @date: 2025/4/5 10:24
 * @description:
 */
public class RedisString {
    public static void main(String[] args) {
        try (JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
             Jedis jedis = jedisPool.getResource()) {
            append(jedis);
        }
    }

    private static void msetAndMget(Jedis jedis) {
        jedis.flushAll();

        jedis.mset("k1", "111", "k2", "222", "k3", "你好");

        List<String> mgetRes = jedis.mget("k1", "k2", "k3", "k4");
        System.out.println(mgetRes);
    }

    private static void setrangeAndGetrange(Jedis jedis) {
        jedis.flushAll();

        jedis.set("k1", "hello world");
        String getrangeRes = jedis.getrange("k1", 6, 10);
        System.out.println(getrangeRes);

        jedis.setrange("k1", 6, "redis");
        System.out.println(jedis.getrange("k1", 0, -1));
    }

    private static void append(Jedis jedis) {
        jedis.flushAll();

        jedis.set("k1", "It's MyGO");

        long appendRes = jedis.append("k1", "!!!!!");
        System.out.println(appendRes);
        System.out.println(jedis.get("k1"));
    }

    private static void incrAndDecr(Jedis jedis) {
        jedis.flushAll();

        jedis.set("k1", "100");
        long incrRes = jedis.incr("k1");
        System.out.println(incrRes);

        jedis.set("k2", "100");
        long decrRes = jedis.decr("k2");
        System.out.println(decrRes);
    }
}
